package com.seanzx.dp.common;

import com.seanzx.dp.entity.Column;
import com.seanzx.dp.serializer.ISerializer;
import com.seanzx.dp.serializer.SerializerFactory;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class DBFileOutputStream extends OutputStream {
    private final FilterOutputStream outputStream;

    public DBFileOutputStream(FilterOutputStream outputStream) {
        this.outputStream = outputStream;
    }

    @Override
    public void write(int b) throws IOException {
        outputStream.write(b);
    }

    public void write(Column column, String value) throws IOException{
        ISerializer serializer = SerializerFactory.getSerializer(column.getType());
        byte[] serialize = serializer.serialize(column, value);
        outputStream.write(serialize);
        outputStream.flush();
    }
}
